<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');

//user auth library

class user_auth {

	// CI global
    protected $ci;

    //construct
    public function __construct()
    {
        $this->ci =& get_instance();
    }

    /**
     * login function
     */
    public function login($username, $password)
    {
        return $this->ci->user_model->login($username, $password);
    }

    /**
     * logout function
     */
    public function logout()
    {
        $this->ci->session->unset_userdata('username');
        $this->ci->session->sess_destroy();
    } 

    /**
     * check for user is logged in ?
     */
    public function logged_in()
    {
        return ($this->ci->session->userdata('username')) ? TRUE : FALSE;
    }
    
    public function allow($roles = FALSE)
    {
        if($roles === FALSE) 
        {
            return FALSE;
        }
        
        foreach($roles as $key => $role)
        {
            if($this->ci->session->userdata('role_name') == $role)
            {
                return TRUE;
            }
        }
        return FALSE;
    }
    
}

/* End of file user_auth.php */
/* Location: ./system/application/libraries/user_auth.php */